package com.crt.uav.rabbitmq.consumer;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import jakarta.annotation.PostConstruct;

@Component
public class UavMessageListenerFactory {

    @Autowired
    private List<ExtChannelAwareMessageListener> listeners;

    private Map<String, ExtChannelAwareMessageListener> listenerMap = new HashMap<>();

    @PostConstruct
    public void init() {
        for (ExtChannelAwareMessageListener listener : listeners) {
            String queueName = listener.getQueueName();
            if (queueName != null) {
                listenerMap.put(queueName, listener);
            }
        }
    }

    public ExtChannelAwareMessageListener getListener(String queueName) {
        return listenerMap.get(queueName);
    }
}
